﻿using QuanLySieuThi.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLySieuThi.Controllers
{
    public class QuanLyMatHang : BaseController<MatHang>
    {
        private static QuanLyMatHang _uniqueObject = null;
        public static QuanLyMatHang UniqueObject
        {
            get
            {
                if (_uniqueObject == null)
                    _uniqueObject = new QuanLyMatHang();
                return _uniqueObject;
            }
        }
        public QuanLyMatHang()
        {
        }

        public override void Delete(string ma)
        {
            //Xóa hóa đơn nhật và hóa đơn xuất trước
            QuanLyHoaDonChiTietNhap.UniqueObject.XoaTheoMaMatHang(ma);
            QuanLyHoaDonChiTietXuat.UniqueObject.XoaTheoMaMatHang(ma);
            base.Delete(ma);
        }

        public int SoLuongHienCo(string p)
        {
            DataTable table = db.ExecuteQuery("select SoLuong from MatHang where MaMatHang = '" + p + "'");
            if (table.Rows.Count > 0)
            {
                string s = table.Rows[0]["SoLuong"].ToString();
                return int.Parse(s);
            }
            return 0;
        }
    }
}
